<template>
    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" :disabled="!disabledSelector>
        <el-form-item label="一级分类">
          <el-select v-model="category1Id" placeholder="请选择">
            <el-option v-for="c1 in categoryStore.category1List" :label="c1.name" :value="c1.id" :key="c1.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select v-model="category2Id" placeholder="请选择">
            <el-option v-for="c2 in categoryStore.category2List"  :label="c2.name" :key="c2.id" :value="c2.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="三级分类">
          <el-select v-model="category3Id" placeholder="请选择">
            <el-option v-for="c3 in categoryStore.category3List" :label="c3.name" :key="c3.id" :value="c3.id" />
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
  </template>
  
  <script lang="ts">
  export default {
    name: 'CategorySelector'
  }
  </script>

  <script lang="ts" setup>
  // @ts-nocheck
  import { reactive , onMounted, computed} from 'vue'
  import { useCategoryListStore } from '@/stores/categoryList';
  
  const categoryStore = useCategoryListStore()

  // 使用计算属性来精简一二级ID 并获取下一级数据
  const category1Id = computed<number>({
  get(){
    return categoryStore.category1Id 
  },
  set(val){
    // 去获取二级导航数据
    categoryStore.getCategory2ListData(val)
  }
})

const category2Id = computed<number>({
  get(){
    return categoryStore.category2Id
  },
  set(val){
    categoryStore.getCategory3ListData(val)
  }
})

const category3Id = computed<number>({
  get(){
    return categoryStore.category3Id
  },
  set(val){
    categoryStore.setCategory3Id(val)
  }
})

  // 设置假数据
  const formInline = reactive({
    user: '',
    region: '',
  })
  
  // 页面挂载一完成就发送请求获取一级导航数据
  onMounted(async()=>{
    // const res = await reqGetCategory1ListData()
    // console.log('cc',res);
    categoryStore.getCategory1ListData()
    
  })

  const onSubmit = () => {
    console.log('submit!')
  }
  </script>
  
  
  <style>
  </style>